package game.screen.option.action;

import game.Person;
import game.manager.ScreenManager;
import game.screen.option.ScreenOption;

public abstract class Action extends ScreenOption {
	protected int moneyChange;
	protected int energyChange;
	protected Person person;

	public Action(String text, int moneyChange, int energyChange, Person person) {
		super(text);
		this.person = person;
		this.moneyChange = moneyChange;
		this.energyChange = energyChange;
	}

	@Override
	public void select() {
		this.result(this.person);

		if (this.energyChange != 0) {
			int energy = this.person.getEnergy();
			this.person.setEnergy(energy + this.energyChange);
		}
		if (this.moneyChange != 0) {
			int money = this.person.getCash();
			this.person.setCash(money + this.moneyChange);
		}

		ScreenManager.getManager().getActiveScreen().refreshScreen();
	}

	@Override
	public String getText() {
		String text = super.getText();
		if (energyChange != 0)
			text += "\t" + energyChange + "E";
		if (moneyChange != 0)
			text += "\t" + "$" + moneyChange;
		return text;
	}

	@Override
	public boolean isEnabled() {
		int cash = this.person.getCash();
		int energy = this.person.getEnergy();
		return (cash + this.moneyChange >= 0)
				&& (energy + this.energyChange >= 0);
	}

	public abstract void result(Person person);
}
